package com.tiancheng.trade.order.controller.app;

import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.order.service.CreditOrderService;
import com.tiancheng.trade.order.vo.api.CreditOrderVo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 移动端退款接口
 *
 * @author kellen
 * @date 2024/6/2
 */
@Slf4j
@RestController
@RequestMapping("/app/creditOrder")
@Validated
public class CreditOrderAppController {

    @Resource
    private CreditOrderService creditOrderService;

    /**
     * 查询免押订单oderStr
     *
     * @param orderId
     * @param compatible 是否兼容老系统请求：Y-是，N—否，如果是则，会再次查询老系统订单
     * @return
     */
    @GetMapping("/getOrderStr")
    public Result<Map<String, String>> getOrderStr(@RequestParam("order_id") String orderId,
                                                   @RequestParam(required = false, value = "compatible") String compatible) {

        String orderStr = creditOrderService.getOrderStr(orderId, compatible);
        Map<String, String> params = new HashMap<>();
        params.put("order_str", orderStr);
        return Result.success(params);
    }


    /**
     * 查询已创建的预授权订单信息
     *
     * @param alipayAuthNo
     * @param compatible   是否兼容老系统请求：Y-是，N—否，如果是则，会再次查询老系统订单
     * @return
     */
    @GetMapping("/queryCreditOrder")
    public Result<CreditOrderVo> queryCreditOrder(@RequestParam("alipay_auth_no") String alipayAuthNo,
                                                  @RequestParam(required = false, value = "compatible") String compatible) {
        return creditOrderService.queryCreditOrderByAlipayAuthNo(alipayAuthNo, compatible);
    }

}
